"""
@author: 周末
--------------------------------------
@project: application
--------------------------------------
@contact:15892766524@163.com
--------------------------------------
@file: json_path.py
--------------------------------------
@time: 2021/11/19 12:58
--------------------------------------
"""
import jsonpath


class KeyWord:
    @staticmethod
    def get_key_words(source, keyword: str, isComplex=False):
        """
        获取JSON数据关键字的值
        :param source: 数据源
        :param keyword: 关键字
        :param isComplex: 是否返回多个
        :return: 关键的值
        """
        try:
            if isComplex is False:
                return jsonpath.jsonpath(source, f'$..{keyword}')[0]
            else:
                return jsonpath.jsonpath(source, f'$..{keyword}')
        except Exception as e:
            pass
